package cn.zhaoyan.servlet;

import cn.zhaoyan.bean.PageBean;
import cn.zhaoyan.service.CustomerService;
import cn.zhaoyan.serviceimpl.CustomerServiceipml;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Map;

@WebServlet(urlPatterns = "/FindServlet")
public class FindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");

        //获取页，页面提交的所有数据什么都拿到，具体要什么调用什么 pageNum name password
        Map<String, String[]> parameterMap = request.getParameterMap();

        PageBean pageBean = new PageBean();
        try {
            BeanUtils.populate(pageBean,parameterMap);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
      //下面就是注入业务层调用业务层的方法、
        CustomerService customerServiceimpl = new CustomerServiceipml();
        PageBean customerService = customerServiceimpl.findCustomerService(pageBean,parameterMap);
        //进行带参数转发
        request.setAttribute("pageBean",customerService);
        request.setAttribute("parameterMap",parameterMap);
        request.getRequestDispatcher("hello.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     doPost(request,response);
    }
}
